(function () {
    "use strict";

    app.filter('linkify', function () {
        return function (text) {
            if (!text) return "";
            var urlRegex = /((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)/g;
            var shopRegex = /@([a-zA-Z0-9_]{1,100})/g;
            var hashTagRegex = /\B#([\w|áàâäãåçéèêëíìîïñóòôöõúùûüýÿæœÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜÝŸÆŒ\']+)/gi;

            text = text.replace(urlRegex, " <a href='$&' target='_blank'>$&</a>").trim();
            text = text.replace(shopRegex, "<a href=#shop/$1'>@$1</a>");
            text = text.replace(hashTagRegex, "<a href='#search/$1'>#$1</a>");

            return text;
        };
    });

})();